import { BaseWindow } from "../../../component/window/BaseWindow";
import { ILayer } from "../../../mvc/interfaces/ILayer";
import { Language } from "../../../../extend/language/Language";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { DisplayUtil } from "../../../common/DisplayUtil";
import { DataProvider } from "../../../../fl/data/DataProvider";
import { SCrossMassacreChoose } from "../../../../Message/Public/SCrossMassacreChoose";
import { ClockManager } from "../../manager/ClockManager";
import { CrossMassacreServerData } from "./data/CrossMassacreServerData";
import { ObjCreate } from "../common/ObjCreate";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { ImagesConst } from "../../resource/ImagesConst";
import { ToolTipsManager } from "../../../../com/mui/manager/ToolTipsManager";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { CrossMassacreServerRender } from "./render/CrossMassacreServerRender";
import { ResFileConst } from "../../resource/ResFileConst";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { GTileList } from "../../../../com/mui/controls/GTileList";
import { ImgBtn } from "../copy/btn/ImgBtn";
import { GTextFiled } from "../../../../com/mui/controls/GTextFiled";
import { SecTimerView } from "../common/SecTimerView";
//class CrossMassacreEnterWin
    
    export  class CrossMassacreEnterWin extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            this.setSize(780, 558);
            this.title = Language.getString(80484);
            this.titleHeight = 27;
            return;
        }

        /* internal  */clickEnterHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.CrossMassacreEnterReq));
            return;
        }

        public /* override */ dispose(arg1: Boolean=true): void
        {
            super.dispose(arg1);
            if (this._btnEnter != null) 
            {
                this._btnEnter.removeEventListener(flash.events.MouseEvent.CLICK, this.clickEnterHandler);
                this._btnEnter = null;
            }
            DisplayUtil.removeAndDisposeAllGUIComponent(this);
            return;
        }

        public updateServerList(arg1: DataProvider): void
        {
            this._serverList.selectedIndex = -1;
            this._serverList.dataProvider = arg1;
            this._serverList.drawNow();
            return;
        }

        public updateEnterCountDown(arg1: SCrossMassacreChoose): void
        {
            if (arg1 == null) 
            {
                return;
            }
            var loc1=arg1.endDt.time - ClockManager.instance.nowDate.time;
            loc1 = loc1 / 1000;
            if (loc1 <= 0) 
            {
                return;
            }
            this._enterCountdown.setLeftTime(loc1);
            return;
        }

        public updateMassacreData(arg1: CrossMassacreServerData): void
        {
            if (arg1 == null) 
            {
                return;
            }
            this._txtMassacreName.text = arg1.serverName;
            this._txtMassacreServerGold.htmlText = Language.getStringByParam(80487, arg1.countryMoney.toString());
            this._txtMassacreKillers.htmlText = Language.getStringByParam(80494, arg1.getMassacreServerNames("<br>          "));
            this._txtMassacreWinGot.text = Language.getStringByParam(80489, arg1.loseWinPercentage);
            return;
        }

        public updateDefenceData(arg1: CrossMassacreServerData): void
        {
            if (arg1 == null) 
            {
                return;
            }
            this._txtDefenceServerGold.htmlText = Language.getStringByParam(80487, arg1.countryMoney.toString());
            this._txtDefenceKillers.htmlText = Language.getStringByParam(80488, arg1.getMassacreServerNames("  "));
            this._txtDefenceLose.text = Language.getStringByParam(80492, arg1.loseWinPercentage);
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            this.initUp();
            this.initMiddle();
            this.initBottom();
            this.loadResource();
            return;
        }

        /* internal  */initUp(): void
        {
            var loc1=null;
            loc1 = ObjCreate.createBitmap(null, 17, 37, this);
            LoaderHelp.setBitmapdata(ImagesConst.CrossMassacreBg1 + ".swf", loc1);
            this._btnHelp = ObjCreate.createImgBtn(ImagesConst.RuleExplain, 670, 42, 60, 23, this, "Button");
            ToolTipsManager.register(this._btnHelp, null, Language.getString(80509));
            return;
        }

        /* internal  */initMiddle(): void
        {
            var loc1=null;
            ObjCreate.createFlowerBg(17, 137, 747, 301, this);
            this._bmpSelectLabel = ObjCreate.createBitmap(null, 213, 142, this);
            ObjCreate.createGTextField(HTMLUtil.addColor(Language.getString(80485), GlobalStyle.green), 548, 148, 190, 20, this, null, true);
            ObjCreate.createBg(22, 170, 264, 264, this);
            ObjCreate.createBg(290, 170, 264, 264, this);
            loc1 = ObjCreate.createBitmap(null, 556, 170, this);
            LoaderHelp.setBitmapdata(ImagesConst.CrossMassacreBg2 + ".swf", loc1);
            this._serverList = ObjCreate.createTileList(33, 185, 525, 252, this);
            this._serverList.setSharedStyle("cellRenderer", CrossMassacreServerRender);
            this._serverList.columnWidth = 242;
            this._serverList.rowHeight = 20;
            this._serverList.verticalGap = 18;
            this._serverList.horizontalGap = 23;
            this._serverList.mouseChildren = true;
            this._serverList.mouseEnabled = true;
            var loc2=GlobalStyle.textFormat6;
            this._txtMassacreName = ObjCreate.createGTextField("", 665, 182, 200, 20, this, loc2);
            this._txtMassacreServerGold = ObjCreate.createGTextField("", 578, 208, 200, 20, this);
            loc2 = GlobalStyle.textFormat6;
            loc2.leading = 5;
            this._txtMassacreKillers = ObjCreate.createGTextField("", 578, 227, 280, 80, this, loc2);
            this._txtMassacreKillers.multiline = true;
            this._txtMassacreKillers.wordWrap = true;
            ObjCreate.createBg(565, 279, 170, 1, this, ImagesConst.SplitLine);
            this._bmpWin1 = ObjCreate.createBitmap(null, 578, 283, this);
            loc2 = GlobalStyle.textFormat6;
            this._txtMassacreWinGot = ObjCreate.createGTextField("", 610, 293, 200, 20, this, loc2);
            this._bmpLost1 = ObjCreate.createBitmap(null, 578, 322, this);
            ObjCreate.createGTextField(Language.getString(80490), 610, 330, 200, 20, this, loc2);
            this._enterCountdown = ObjCreate.createSecTimeView(HTMLUtil.addColor(Language.getString(80495), GlobalStyle.green), 575, 412, 220, 20, this);
            return;
        }

        /* internal  */initBottom(): void
        {
            ObjCreate.createBg(17, 442, 747, 105, this);
            this._bmpDefence = ObjCreate.createBitmap(null, 345, 447, this);
            ObjCreate.createBg(243, 467, 305, 1, this, ImagesConst.SplitLine);
            this._bmpDefenceIcon = ObjCreate.createBitmap(null, 25, 475, this);
            var loc1=GlobalStyle.textFormat6;
            loc1.bold = true;
            loc1.size = 18;
            ObjCreate.createGTextField(Language.getString(80486), 100, 478, 140, 20, this, loc1);
            loc1 = GlobalStyle.textFormat6;
            this._txtDefenceServerGold = ObjCreate.createGTextField("", 100, 501, 200, 20, this, loc1);
            this._txtDefenceKillers = ObjCreate.createGTextField("", 100, 521, 300, 20, this, loc1);
            loc1 = GlobalStyle.textFormat6;
            ObjCreate.createGTextField(Language.getString(80491), 393, 482, 200, 20, this, loc1);
            this._txtDefenceLose = ObjCreate.createGTextField("", 393, 518, 200, 20, this, loc1);
            ObjCreate.createBg(533, 474, 1, 65, this, ImagesConst.VSpliteLine);
            loc1 = GlobalStyle.textFormat5;
            loc1.leading = 3;
            var loc2=ObjCreate.createGTextField("", 551, 485, 200, 80, this, loc1);
            loc2.multiline = true;
            loc2.wordWrap = true;
            loc2.text = Language.getString(80496);
            this._bmpWin2 = ObjCreate.createBitmap(null, 360, 471, this);
            this._bmpLost2 = ObjCreate.createBitmap(null, 360, 510, this);
            return;
        }

        /* internal  */loadResource(): void
        {
            LoaderHelp.addResCallBack(ResFileConst.arena, this.arenaResGotHandler);
            LoaderHelp.addResCallBack(ResFileConst.IntegralShopBtn, this.integralShopGotHandler);
            return;
        }

        /* internal  */integralShopGotHandler(): void
        {
            LoaderHelp.addResCallBack(ResFileConst.CrossMassacre, this.massacreResGotHandler);
            return;
        }

        /* internal  */arenaResGotHandler(): void
        {
            this._bmpWin1.bitmapData = GlobalClass.getBitmapData(ImagesConst.ArenaWinSmall);
            this._bmpWin2.bitmapData = GlobalClass.getBitmapData(ImagesConst.ArenaWinSmall);
            this._bmpLost1.bitmapData = GlobalClass.getBitmapData(ImagesConst.ArenaLoseSmall);
            this._bmpLost2.bitmapData = GlobalClass.getBitmapData(ImagesConst.ArenaLoseSmall);
            return;
        }

        /* internal  */massacreResGotHandler(): void
        {
            this._bmpSelectLabel.bitmapData = GlobalClass.getBitmapData(ImagesConst.CrossMassacre_Selecte);
            this._btnEnter = ObjCreate.createImgBtn(ImagesConst.CrossMassacre_EnterLabel, 577, 363, 154, 46, this, "IntegralShopBtn");
            this._btnEnter.addEventListener(flash.events.MouseEvent.CLICK, this.clickEnterHandler);
            this._bmpDefence.bitmapData = GlobalClass.getBitmapData(ImagesConst.CrossMassacre_DefenceLabel);
            this._bmpDefenceIcon.bitmapData = GlobalClass.getBitmapData(ImagesConst.CrossMassacre_Defence);
            return;
        }

        /* internal */ /* var */_serverList: GTileList;

        /* internal */ /* var */_btnHelp: ImgBtn;

        /* internal */ /* var */_txtMassacreName: GTextFiled;

        /* internal */ /* var */_txtMassacreServerGold: GTextFiled;

        /* internal */ /* var */_txtMassacreKillers: GTextFiled;

        /* internal */ /* var */_txtMassacreWinGot: GTextFiled;

        /* internal */ /* var */_btnEnter: ImgBtn;

        /* internal */ /* var */_enterCountdown: SecTimerView;

        /* internal */ /* var */_bmpWin1: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_bmpLost1: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_bmpSelectLabel: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_bmpDefence: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_bmpDefenceIcon: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_txtDefenceServerGold: GTextFiled;

        /* internal */ /* var */_txtDefenceKillers: GTextFiled;

        /* internal */ /* var */_bmpLost2: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_bmpWin2: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_txtDefenceLose: GTextFiled;
    }
